#include "chap12.h"
#include <stdio.h>
#include <pthread.h>

int main() {
	pthread_t threads[20];
	long t;
	for (t = 0; t < 5; t++) {
		if (pthread_create(&threads[t], NULL, do_stuff, (void*)t) == -1) {
			char msg[32];
			sprintf(msg, "Can't create thread t%ld", t);
			error(msg);
		}
	}
	void* result;
	for (t = 0; t < 5; t++) {
		if (pthread_join(threads[t], &result) == -1) {
			char msg[32];
			sprintf(msg, "Can't join thread t%ld", t);
			error(msg);
		}
		printf("Thread %ld returned %ld\n", t, (long)result);
	}

	return 0;
}

